import { ref } from "vue";
import type { InjectionKey } from "vue";

export const engine = ref();

export interface DeviceInfo {
  no: string;

  description: string;

  // 扩展数据
  extra: string;
}

export interface SceneManager {
  restoreView(): void;
  switchView(): void;
  currentView: Views;
  defaultView: Views;
}

export interface EventDeviceInfo {
  deviceInfo: DeviceInfo;
  nextDeviceInfo: DeviceInfo;
}

export interface SceneInfo {
  name: string;
  displayName: string;
  disabled: boolean;
  visibleInFootBar: boolean;
  index: number;
  active: boolean;
  isDefault?: boolean;
  view?: Views;
}

export enum SceneEventType {
  DeviceSelected = "onDeviceSelected",
  DeviceUnselected = "onDeviceUnselected",
}
export interface EventMap {
  [SceneEventType.DeviceSelected]: (event: EventDeviceInfo) => void;
  [SceneEventType.DeviceUnselected]: (event: EventDeviceInfo) => void;
}

export enum Views {
  // 俯视图
  lookdownView = 1,
  // 前视图,
  frontView = 2,
}

// 系统支持的所有的场景
export const scenes: SceneInfo[] = [
  {
    name: "外景",
    displayName: "外景",
    disabled: false,
    visibleInFootBar: false,
    index: 1,
    active: false,
    isDefault: false,
    view: Views.frontView,
  },
  {
    name: "原材料仓",
    displayName: "原材料仓",
    disabled: false,
    visibleInFootBar: true,
    index: 1,
    active: false,
    view: Views.lookdownView,
  },
  {
    name: "绕组车间",
    displayName: "绕组车间",
    disabled: false,
    visibleInFootBar: true,
    index: 1,
    active: false,
    view: Views.lookdownView,
  },
  {
    name: "铁心车间",
    displayName: "铁心车间",
    disabled: false,
    visibleInFootBar: true,
    index: 1,
    active: false,
    view: Views.lookdownView,
  },
  {
    name: "绝缘车间",
    displayName: "绝缘车间",
    disabled: false,
    visibleInFootBar: true,
    index: 1,
    active: false,
    view: Views.lookdownView,
  },
  {
    name: "烘房",
    displayName: "烘房",
    disabled: false,
    visibleInFootBar: true,
    index: 1,
    active: false,
    view: Views.lookdownView,
  },
  {
    name: "油箱车间",
    displayName: "油箱车间",
    disabled: false,
    visibleInFootBar: true,
    index: 1,
    active: false,
    view: Views.lookdownView,
  },
  {
    name: "器身车间",
    displayName: "器身车间",
    disabled: false,
    visibleInFootBar: true,
    index: 1,
    active: false,
    view: Views.lookdownView,
  },
  {
    name: "试验大厅",
    displayName: "试验大厅",
    disabled: false,
    visibleInFootBar: true,
    index: 1,
    active: true,
	isDefault: true,
    view: Views.lookdownView,
  },
];

export function getDefaultScene(): SceneInfo {
  for (const item of scenes) {
    if (item.isDefault) {
      return item;
    }
  }
  return scenes[0];
}
export interface SceneViewerConfig {
  serverPath: string;
  polyfillsPath?: string;
  systemjsPath?: string;
  settingsPath?: string;
  assetsPath?: string;
  imports?: Record<string, string>;
}

export const defaultConfig: SceneViewerConfig = {
  serverPath: "",
  polyfillsPath: "${serverPath}/src/polyfills.bundle.js",
  systemjsPath: "${serverPath}/src/system.bundle.js",
  settingsPath: "${serverPath}/src/settings.json",
  imports: {
    cc: "${serverPath}/cocos-js/cc.js",
    "wait-for-ammo-instantiation":
      "${serverPath}/cocos-js/wait-for-ammo-instantiation.js",
  },
  assetsPath: "${serverPath}/",
};
export const SceneViewerConfigKey: InjectionKey<SceneViewerConfig> = Symbol(
  "SceneViewerConfigKey"
);
